package com.bw.mvp

import android.os.Bundle
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.bw.mvp.http.ApiService
import com.bw.mvp.http.RetrofitManager
import com.bw.mvp.model.BaseResponse
import com.bw.mvp.model.PostListModel
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

/**
 * 1。网络：okhttp+retrofit+rxjava
 * 2.mvp：
 * model层
 * view层
 * presenter层:p持有view
 * contract接口协议层
 * 3.数据传递：P通过接口回调给V
 */
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        
        val api = RetrofitManager.getInstance().retrofit.create(ApiService::class.java)
        api.getPostList(1,20)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<BaseResponse<PostListModel>> {
                override fun onSubscribe(p0: Disposable) {

                }

                override fun onError(p0: Throwable) {
                    Toast.makeText(this@MainActivity,p0.message.toString(),Toast.LENGTH_SHORT).show()
                }

                override fun onComplete() {

                }

                override fun onNext(p0: BaseResponse<PostListModel>) {
                   Toast.makeText(this@MainActivity,p0.data.toString(),Toast.LENGTH_SHORT).show()
                }

            })
    }
}